package 动态规划;
import java.util.Arrays;
public class 完全平方数 {
    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        Arrays.fill(dp,10001);
        dp[0] = 0;
        dp[1] = 1;
        for (int i = 2; i <=n ; i++) {
            for (int j = 1; j*j <= i; j++) {
                dp[i] = Math.min(dp[i],dp[i-j*j]+1);
            }
        }
        return dp[n];
    }
}
